package cn.smartopen.aispace.service.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.smartopen.aispace.base.BaseService;
import cn.smartopen.aispace.config.Config;
import cn.smartopen.aispace.entity.TokenEntity;
import cn.smartopen.aispace.mapper.TokenMapper;
import cn.smartopen.aispace.utils.Utils;


@Service
public class UserService extends BaseService {

    @Autowired
    TokenMapper tokenMapper;

    public TokenEntity createToken(String tokenStr, String publicKey) {
        if(publicKey.startsWith("0x")){
            publicKey = publicKey.substring(2);
        }
        Long expireTimeStamp = Utils.getCurrentTimeStamp() + Config.TOKEN_EFFECTIVE_TIME;
        var tokenEntity = new TokenEntity(tokenStr,expireTimeStamp,publicKey);

        tokenMapper.createTokenEntity(tokenEntity);
        
        return tokenEntity;

    }
    
}
